<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Report extends CCMIS_Controller{
    public function __construct() {
        parent::__construct();
        $this->load->model('mdl_rmis');
        //dito iloload ung mga model na kakailanganin ng Account Controller. better have this constructor.
    }

    public function index()
    {
    	$this->oldreport();
    }
	public function newreport(){
		$data = array(
           'page_title' => 'RMIS | Report'
        );
		$this->setup_view('rmis/report/newreport', $data);
	}
	public function oldreport(){
		$data = array(
           'page_title' => 'RMIS | Report'
        );
		$this->setup_view('rmis/report/oldreport', $data);
	}
	public function getResearcherType($researcher){
		$type = array();
		
		foreach($researcher as $temp){
			if($temp == 0){
				$type[sizeof($type)] = "undergraduate";
			}//if
			else{
				$type[sizeof($type)] = "graduate";
			}//else
		}//foreach
		
		return $type;
	}//getResearcherType

	public function getDateInterval($dateFilterType,$date1,$date2){
		$dateInterval = null;
		switch($dateFilterType){
			case 1:
				$dateInterval= "during ".$date1;
				break;
			case 2:
				$dateInterval = $date1." to ".date("Y-m-d", time());
				break;
			case 3:
				$dateInterval = "2007-01-01 to ".$date1;
				break;
			case 4:
				$dateInterval = $date1." to ".$date2;
				break;
		}//switch
		
		return $dateInterval;
	}//function

	public function generate(){
		$repo = $this->input->post('report-type');
		$data = array(
           'page_title' => 'RMIS | Report',
           'facultyPerformance' => null,
           'reportTitle' => null,
           'topResearch' => null,
           'leastResearch' => null,
           'reportType' => $this->input->post('report-type')
        );

		if(isset($_POST['btngenerate'])){
			switch($repo){
				case 1:
					
					$date1 = $_POST['year-1']."-".$_POST['month-1']."-".$_POST['day-1'];
					$date2 = null;
					
					if(isset($_POST['year-2']) && isset($_POST['month-2']) && isset($_POST['day-2'])){
						$date2 = $_POST['year-2']."-".$_POST['month-2']."-".$_POST['day-2'];
					}//if
					
					$reportTitle = "CCIS RESEARCH PERFORMANCE REPORT - ";
					$reportTitle = $reportTitle.implode(", ", getResearcherType($_POST['researcher']));
					$reportTitle = $reportTitle."<br />(".getDateInterval($_POST['date'],$date1,$date2).")";
					break;
				case 2:
				
					$date1 = $_POST['year-1']."-".$_POST['month-1']."-".$_POST['day-1'];
					$date2 = null;
					
					if(isset($_POST['year-2']) && isset($_POST['month-2']) && isset($_POST['day-2'])){
						$date2 = $_POST['year-2']."-".$_POST['month-2']."-".$_POST['day-2'];
					}//if
					$facultyPerformance = getFacultyPerformance($_POST['department'],$_POST['date'],$date1,$date2);
					
					$reportTitle="CCIS FACULTY RESEARCH PERFORMANCE REPORT - ";
					$reportTitle = $reportTitle.implode(", ",$_POST['department']);
					
					$reportTitle = $reportTitle."<br />(".getDateInterval($_POST['date'],$date1,$date2).")";
					break;
				case 3:
					$date1 = $_POST['year-1']."-".$_POST['month-1']."-".$_POST['day-1'];
					$date2 = null;
					
					if(isset($_POST['year-2']) && isset($_POST['month-2']) && isset($_POST['day-2'])){
						$date2 = $_POST['year-2']."-".$_POST['month-2']."-".$_POST['day-2'];
					}//if
					

					$topResearch = getTopFields($_POST['top-list'],'desc',$_POST['researcher'],$_POST['department'],
						$_POST['date'],$date1,$date2);
					$leastResearch = getTopFields($_POST['top-list'],'asc',$_POST['researcher'],$_POST['department'],
						$_POST['date'],$date1,$date2);
						
					$reportTitle = "CCIS RESEARCH TRENDS AND DEFICIENCIES REPORT - ";
					$reportTitle = $reportTitle.implode(", ",$_POST['department']);
					$reportTitle = $reportTitle."<br/>".implode(", ", getResearcherType($_POST['researcher']));
					
					$reportTitle = $reportTitle."<br />(".getDateInterval($_POST['date'],$date1,$date2).")";
					break;	
			}
		}  
		echo $repo;
		$this->setup_view('rmis/report/generate', $data);
	}

	
	
}
?>